package net.csdra.wenhua.nanan.qiandao.domain;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.sql.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by xiaomi on 2017/2/20.
 */
public interface UserRepository extends JpaRepository<User, String> {

    List<User> findByWeixinId(String weixinId);

    //    @Query("SELECT C.userId as userId, U.userInfo as userInfo, COUNT(C.id) as totalCheckInNum  \n" +
//            "FROM checkIn C,user U \n" +
//            "WHERE U.id = C.userId AND C.checkInTime BETWEEN ?1 AND ?2  \n" +
//            "GROUP BY C.userId")
//    Page<Map<String, Object>> findRecords(Date from, Date to, Pageable pageable);
    @Query("SELECT new net.csdra.wenhua.nanan.qiandao.domain.Record(C.userId,U.userInfo,COUNT(C.id))  \n" +
            "FROM checkIn C,user U \n" +
            "WHERE U.id = C.userId AND C.checkInTime BETWEEN ?1 AND ?2  \n" +
            "GROUP BY C.userId")
    Page<Record> findRecords(Date from, Date to, Pageable pageable);
}
